<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    
<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;sensor=false&amp;key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA" type="text/javascript"></script>
    <script type="text/javascript">
    var map;
    var geocoder;

    function initialize() {
      map = new GMap2(document.getElementById("map_canvas"));
      //map.setCenter(new GLatLng(34, 0), 15);
      geocoder = new GClientGeocoder();
      var address = document.getElementById("addr").value.substr(0, 1).toUpperCase() + document.getElementById("addr").value.substr(1);
      var cost = "<br>Average Cost of Living: $" + document.getElementById("cost").value;
     //document.write(address + ", lol<br>");
      showAddress(address, cost);
    }
    
    
    function showAddress(address, desc) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
          GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml("<b>" + address + "</b>" + desc);
          });
              return point;
            }
          }
        );
        return false;
      }
    }

    
    // showLocation() geocodes the address entered 
    // and adds a marker to the map at that location.
    </script>
  </head>

  <body onload="initialize()">
<?php
require_once("functions.php");
require_once("database.php");
if($_GET and isset($_GET['id']) and is_numeric($_GET['id'])){
$safe_id = sql_escape($_GET['id']);
  $address = query_select("
    SELECT name
    FROM city
    WHERE id = " . $safe_id );
      $today = time();
    $days = 14;
        $day_min = $today - (($days) * 60 * 60 * 24);
    $day_max = $today;
        $sql = "
      SELECT ROUND(AVG(price), 2) AS avg_price
      FROM apartment
      WHERE date >= " . $day_min . "
      AND date < " . $day_max . "
      AND city_id = " . sql_escape($_GET['id']);

//    echo $sql;
    $prices = query_select($sql);
    $average_price = $prices[0]['avg_price'];
//    echo $average_price;
//echo $address[0]['name'];
echo "<form>
	<input type=\"hidden\" id= \"addr\" value=\"".$address[0]['name']."\">
  <input type=\"hidden\" id= \"cost\" value=\"".$prices[0]['avg_price']."\">
	</form>
";
}


?>
<div id="map_canvas" style="width: 500px; height: 300px"></div>

</body>
</html>



